﻿@using Pay.Core;
@model order_dto
@{
    ViewBag.Title = "发货";
    Layout = "~/Views/Shared/_MallLayout.cshtml";
    var img_url = ViewBag.img_url;
    var expressList = ViewBag.ExpressList as List<DropdownItem>;
    long curUserId = ViewBag.CurUserId;
}

<body class="page-shoppingCart page-cartConfirm page-order page-orderDeliver">
    <div class="orderAddress mb10">
        <div class="box">
            <i class="icon-loca"></i>
            <div class="lineBg"></div>
            <div class="top fn30 mb20">
                买家收货地址：
            </div>
            <p class="fn30 mb10">
                <span class="mr20">@Model.shipping.ship_to</span>
                @Model.shipping.phone
            </p>
            <p class="col-gray fn26">@Model.shipping.region_name @Model.shipping.address</p>
        </div>
    </div>

    <div class="mod-orderDetail mb10">
        <ul>
            <li>
                @foreach (var item in Model.order_items) {
                    <div class="innerItem innerItemWhite">
                        <div class="img">
                            @if (item.order_item_type != 6) {
                                <img src="@(item.product.main_image_url != null ? item.product.main_image_url : img_url + item.product.first_image)" />
                            } else {
                                <img src="@(img_url +item.bazaar_product.main_img)" />
                            }
                        </div>
                        <div class="text">
                            <p class="fn28 col-gray1 tit mb10">
                                @if (item.order_item_type != 6) {@item.product.name} else {@item.bazaar_product.product_name}
                            </p>
                            <div class="col-gray mb10">
                                <span class="mr20">@item.sku_name</span>
                            </div>
                            <div class="price">
                                @if (item.unit_price > 0) {
                                    <em class="fn22">￥</em>
                                    <span class="fn28 itemPrice">@item.unit_price.ToString("0.##")</span>
                                }
                                @if (item.unit_price > 0 && item.red_drill > 0) {
                                    <em class="fn22">+</em>
                                }
                                @if (item.red_drill > 0) {
                                    <span class="fn28 itemPrice">@item.red_drill.ToString("0.######")</span>
                                    <em class="fn22">红钻</em>
                                }
                                <span class="fn-right quantity">
                                    <em class="col-gray">×</em> <em class="j-quantity">@item.quantity</em>
                                </span>
                            </div>
                        </div>
                    </div>
                }
                <div class="mb30"></div>
            </li>
        </ul>
    </div>

    <div class="mod-orderDetail">
        <ul>
            <li>
                <div class="block fn28 message">
                    <span class="lable">买家留言</span>
                    @if (string.IsNullOrEmpty(Model.remark)) {
                        <div class="hidden col-gray ">
                            暂无留言
                        </div>
                    } else {
                        <div class="hidden">
                            @Model.remark
                        </div>
                    }
                </div>
                <div class="block fn28 borderTop message">
                    <span class="lable">物流公司</span>
                    <div class="hidden text-right">
                        <span class="mr20" id="deliver">请选择物流公司</span>
                        <i class="icon-go"></i>
                    </div>
                </div>
                <div class="block fn28 borderTop message ">
                    <span class="lable">快递单号</span>
                    <div class="flex">
                        <input id="ship_order_number" class="textInput flex-1" type="text" placeholder="请输入快递单号">
                        <a href="javascript:richScan();"><i class="icon-ewm"></i></a>
                    </div>
                </div>
                <div class="block col-gray fn28">
                    暂时无法按照城市距离商品重量设定快递费用，运费有可能也会有所差异，如果需要补充邮费请您主动联系买家补充！
                    <br><br><br>
                    <div>
                        <div class="w50">
                            <a href="javascript:cancelDelivery()" class="ui-btn ui-btn-border ui-btn-big mr10">取消</a>
                        </div>
                        <div class="w50">
                            <a href="javascript:confirmDelivery()" class="ui-btn ui-btn-buy flex-1 ml10">确定</a>
                        </div>
                    </div>
                </div>
            </li>
        </ul>
    </div>

    <div class="lt-pop">
        <input id="value" type="hidden">
        <div class="mask"></div>
        <div class="panel trans_3" style="max-height: 50%;overflow-y: auto;">
            <ul id="express_li">
                <li class="cur">
                    选择物流公司<i class="icon-gou fn-right"></i>
                </li>
                @if (expressList != null) {
                    foreach (var express in expressList) {
                        <li data-text="@express.Text" data-value="@express.Value">
                            @express.Text<i class="icon-gou fn-right"></i>
                        </li>
                    }
                }
            </ul>
        </div>
    </div>

    <script type="text/javascript">
        function confirmDelivery() {
            if ($('#express_li .cur') == undefined || $('#express_li .cur').length > 1) {
                layer.msg("请刷新页面");
                return false;
            }
            var express_li = $("#express_li .cur")[0];
            if ($(express_li).attr('data-text') == undefined || $(express_li).attr('data-text') == '') {
                layer.msg("请选择物流公司");
                return false;
            }
            var ship_order_number = $("#ship_order_number").val();
            if (ship_order_number == undefined || ship_order_number == '') {
                layer.msg("请输入快递单号");
                return false;
            }
            var order_no = '@Model.order_no';
            var express_company_name = $(express_li).attr('data-text') ;
            var express_no = $(express_li).attr('data-value') ;
            swal({
                title: "您确定要发货该订单吗？",
                showCancelButton: true,
                confirmButtonColor: "",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: true
            },
                function (isConfirm) {
                    if (isConfirm) {
                        $.ajax({
                            url: '@Url.Action("OrderDelivery", "MyOrder")',
                            type: 'POST',
                            async: false,
                            data: { order_no: order_no, express_no: express_no, express_company_name: express_company_name, ship_order_number: ship_order_number },
                            success: function (response) {
                                if (response.result_code == 1000) {
                                    layer.msg(response.result_msg);
                                    setTimeout(function () {
                                        window.location.href = '/MyOrder/SellerOrderDetail?order_id=@Model.id';
                                            //window.location.reload();
                                        }, 300);
                                }
                                else {
                                        layer.msg(response.result_msg);
                                }
                            }
                        });
                    } else {
                        layer.msg("发货失败");
                    }

                });


        }
        function cancelDelivery() {
            window.location.href = '/MyOrder/SellerOrderDetail?order_id=@Model.id';
        }
    </script>

    <script>
        $(function () {
            $("#deliver").click(function () {
                $('.lt-pop').addClass('cur');
                $('.panel').addClass('show');
            });
            $(".mask").click(function () {
                setTimeout("$('.lt-pop').removeClass('cur');", 300);
                $('.panel').removeClass('show');
            });

            $('.lt-pop li').click(function () {
                $(this).addClass('cur').siblings('li').removeClass('cur');
                // var i = $(this).index();
                // $('#value').val(i);
                var textCon = $(this).text();
                $('#deliver').text(textCon);

                setTimeout("$('.lt-pop').removeClass('cur');", 300);
                $('.panel').removeClass('show');
            })
        })
    </script>

    <!--扫一扫-->
    <script type="text/javascript">
        //防止后退
        var browser = {
            versions: function () {
                var u = navigator.userAgent, app = navigator.appVersion;
                return {
                    //移动终端浏览器版本信息
                    trident: u.indexOf('Trident') > -1, //IE内核
                    presto: u.indexOf('Presto') > -1, //opera内核
                    webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                    gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                    mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                    ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                    android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
                    iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                    iPad: u.indexOf('iPad') > -1, //是否iPad
                    webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部,
                    WeiXin: u.match(/MicroMessenger/i) == "MicroMessenger" //是否为微信客户端
                };
            }(),
            language: (navigator.browserLanguage || navigator.language).toLowerCase()
        };
        //扫一扫
        function richScan() {
            try {
                if (browser.versions.ios) {
                    window.webkit.messageHandlers.richScan.postMessage("");
                } else if (browser.versions.android) {
                    androidfuntion.richScan();
                }
            } catch (e) {
                layer.msg("请下载最新版本APP，扫一扫快递单");
            }
        }
        //扫一扫结果
        function getPhoneScanResult(scanResult) {
            $("#ship_order_number").val(scanResult);
        }
    </script>
</body>
